1. Field of the Invention
The invention relates to the technical field of file systems and, more particularly, to a recycle-free directory entry system and method that is used in a file system.
2. Description of Related Art
As semiconductor processes have developed rapidly, more transistors can be contained in a same area such that electronic devices have the enhanced functions and the trend of sizes is toward being light, thin and small. Accordingly, the capacity of a single packaged NAND flash memory is continuously increased, and a hand-held MP3 player with NAND flash memory can rapidly increase the capacity. In order to download MP3 songs from different platforms, the hand-held MP3 player typically implements an internal FAT32 file system.
FIG. 1 is a schematic view of directory entries of a conventional FAT32 file system that are recorded in a storage device. As shown in FIG. 1, the storage device has sectors 11, each providing a memory space to record one or more directory entries 12. As shown, a file 13 in the file system corresponds to one or more directory entries 12. The directory entries 12 record the name and associated data of the corresponding file 13. Searching, deleting and/or adding files are required for operation of the file system, and accordingly the traverse, delete and new functions are provided to the directory entries 12.
FIG. 2 is a flowchart of a traverse operation in the conventional FAT32 file system. As shown in FIG. 2, step S110 reads a sector 11 from the storage device. Step S120 filters a next target directory entry 12 from the sector 11 read, where each directory entry 12 has 32 bytes. Step S130 determines if the directory entry 12 obtained has the first byte containing “0x00”. When the first byte is determined to contain “0x00”, it indicates that the directory entry 12 is not used and not followed by another directory entry 12, and in this case, no traverse is operated and the procedure is ended. When the first byte is determined to not contain a value of 0x00, step 140 is executed. Step S140 further determines if the first byte contains 0xE5. When the first byte is determined to contain 0xE5, it indicates that the directory entry 12 is not used but followed by another directory entry 12, namely, the directory entry 12 corresponds to a deleted file 13, and in this case, step S120 is executed to filter a next directory entry 12. When the first byte is determined to not contain 0xE5, it indicates that the directory entry 12 is used by the file 13, and step S150 is executed to gather a filename in accordance with data read from all directory entries 12 read. Step S160 determines if the filename gathered is complete. When the filename gathered is complete, it indicates that the file 13 is traversed and the procedure is ended. When the filename gathered is not complete, step S170 is executed. Step S170 further determines if the tail of the sector 11 is read. When the tail of the sector 11 is read, step S110 is executed to read a next sector. When the tail of the sector 11 is not read, step S120 is executed to filter a next directory entry 12.
FIG. 3 is a flowchart of a delete operation in the conventional FAT32 file system. As shown in FIG. 3, step S210 reads a sector 11 from the storage device. Step S220 filters a next directory entry 12 from the sector 11 read, where each directory entry 12 has 32 bytes. Step S230 determines if the directory entry 12 obtained has the first byte containing “0x00”. When the first byte is determined to contain “0x00”, it indicates that the directory entry 12 is not used and not followed by another directory entry 12, and in this case, no directory entry 12 can be deleted and the procedure is ended. When the first byte is determined to not contain 0x00, step 240 is executed. Step S240 further determines if the first byte determined contains 0xE5. When the first byte is determined to contain 0xE5, it indicates that the directory entry 12 is not used but followed by another directory entry 12, and in this case, step S220 is executed to filter a next directory entry 12. When the first byte is determined to not contain 0xE5, it indicates that the directory entry 12 is used by the file 13, and step S250 is executed to concatenate data read from all directory entries 12 read to thereby form a filename. Step S260 determines if the filename is a target filename. When the filename is the target filename, step S280 is executed to set the first byte determined to contain 0xE5 to indicate the directory entry 12 is unused. When the filename is not the target filename, step S270 is executed. Step S270 further determines if the tail of the sector 11 is read. When the tail of the sector 11 is read, step S210 is executed to read a next sector. When the tail of the sector 11 is not read, step S220 is executed to filter a next directory entry 12.
FIG. 4 is a flowchart of an appending operation in the conventional FAT32 file system. As shown in FIG. 4, step S310 reads a sector 11 from the storage device. Step S320 filters a next directory entry 12 from the sector 11 read, where each directory entry 12 has 32 bytes. Step S330 determines if the directory entry 12 obtained has the first byte containing “0x00”. When the first byte is determined to contain “0x00”, it indicates that the directory entry 12 is not used and not followed by another directory entry 12, and in this case, step 350 adds a new directory entry 12 immediately after the directory entry 12. When the first byte is determined to not contain 0x00, step 340 is executed. Step S340 further determines if the tail of the sector 11 is read. When the tail of the sector 11 is read, step S310 is executed to read a next sector 11. When the tail of the sector 11 is not read, step S320 is executed to filter a next directory entry 12.
As cited, the conventional FAT32 file system applies one or more directory entries to record the filename and associated data of the file 13, and each directory entry uses 32 bytes. However, the required length is changed because of different filenames, which can have a filename up to 255 characters. Accordingly, a single file 13 may require one to ten directory entries 12, which causes an uncertainty of the use amount of space. When the file system is traversed, the directory entries 12 have to read one by one and determine the contents due to the uncertainty of required length, in order to obtain the complete information for determining if there exists a next directory/file 13 or not and determining where the file 13 is. Such a way takes too much time. In addition, as learned from the flowcharts of FIGS. 2 to 4, the prior art requires plural comparisons, which also make the operation of the directory entries 12 of the typical FAT32 file system waste too much time. Further, the directories/files 13 deleted may release different space lengths thus causing uncertainty, and the space cannot be reused by proceeding files 13 thus causing space waste.
Therefore, it is desirable to provide an improved directory entry system and method to mitigate and/or obviate the aforementioned problems.